package com.mycompany.project.client;

import java.util.LinkedList;

/**
 * @author Laboratorio Tv Collaborativa/Contenuti Digitali --> Sardegna District --> Crs4 --> Sardegna Ricerche
 * 
 * This class implements an item composed of two fields, an integer field and a double field.
 * On this two fields is possible to get and set their values.
 * In @SaStria project the object of this class is typically used for save the pointer at the
 * next active annotation tag. Annotations tags are saved on an array and each element save
 * the start and end time of annotation. During the video play the next possible annotation tag to show 
 * is this that have the start time bigger than the play position time and the smallest start time between all
 * annotations tags bigger than play position. To have a pinter to one of this array elements is necessary to save
 * the pointer of the element(index value in array) and the time start value. 
 * 
 */
public class NextActiveTag {
	
	private int indexValue;    //integer value element. in @SaStria this is the index of next active element in array of annotations elements
	private double timeValue;  // double value element. in @SaStria this is the time start value of next active element in array of annotations elements
		
	
	/**
	 * Constructor of {@link NextActiveTag} class. this constructor sets the value of indexValue and timeValue elements 
	 * @param iv : integer value for setting indexValue item
	 * @param tv : double value for setting timeValue item
	 */
	public NextActiveTag(int iv, double tv) {
		indexValue=iv;
		timeValue=tv;		
	}

	/**
	 * this method gets the indexValue value 
	 * @return the indexValue value 
	 */
	public int getIndexValue(){
		return indexValue;
	}
	
	/**
	 * this method sets the indexValue value 
	 * @param iv: the indexValue to set
	 */
	public void setIndexValue(int iv){
		indexValue=iv;
	}
	
	/**
	 * this method gets the timeValue value 
	 * @return the timeValue value 
	 */
	public double getTimeValue(){
		return timeValue;
	}
	
	/**
	 * this method sets the timeValue value 
	 * @param tv: the timeValue value to set
	 */
	public void setTimeValue(double tv){
		timeValue=tv;
	}
	
	
	/**
	 * this method sets the indexValue and timeValue value 
	 * @param iv : the indexValue value to set
	 * @param tv : the timeValue value to set
	 */
	public void setValues(int iv, double tv) {
		indexValue=iv;
		timeValue=tv;
	}
	
	/**
	 * this method sets the indexValue and timeValue value if the iv parameter value
	 * is smallest than the current value of indexValue or if indexValue is equal to "-1".
	 * @param iv : the indexValue value to set
	 * @param tv : the timeValue value to set
	 */
	public void insertNewTag(int iv, double tv ){
		if((indexValue>iv) || (indexValue==-1)){
				indexValue=iv;
				timeValue=tv;			
		}		
	}
	
	
	/**
	 * this method sets the indexValue and timeValue value if iv parameter value
	 * is smallest or equal to the value of maxIndexValue. 
	 * @param iv : the indexValue value to set
	 * @param annotations : Array of annotation tags element.
	 * @param maxIndexValue : number of annotation tags elements in the annotations array.
	 */
	public void setValues(int iv, LinkedList<Annotation> annotations,int maxIndexValue){
		if(maxIndexValue>=iv){  // if iv is a valid index value of annotations array
				indexValue=iv;  // sets the index value
				timeValue=annotations.get(iv).getTimeStart(); // sets the time value reading this value by annotations array at iv position
		}
		 else{ // in this case the aren't other annotation on array and we are arrived at the last element
			indexValue=-1;
			timeValue=-1;
		}
		
	}
	
	
}
